import {createRouter, createWebHashHistory} from 'vue-router'
import Login from "@/views/Login";
import Index from "@/views/Index";
import {message} from "ant-design-vue";
import Order from "@/Pages/Order/OrdersPage";
import DishPage from "@/Pages/Dish/DishPage";
import AddDishPage from "@/Pages/Dish/AddDishPage";
import UpdateDishPage from "@/Pages/Dish/UpdateDishPage";
import RestPassword from "@/Pages/RestPassword";
import DishCategoriesPage from "@/Pages/DishCategories/DishCategoriesPage";
import CategoriesDetailPage from "@/Pages/DishCategories/CategoriesDetailPage";
import OrdersPage from "@/Pages/Order/OrdersPage";
import MembersPage from "@/Pages/Member/MembersPage";
import RefundOrderPage from "@/Pages/Order/RefundOrderPage";
import RankingListPage from "@/Pages/Dish/RankingListPage";
const routes = [
    {
        path: "/", redirect: "/login"
    },
    {
        path: "/login",
        name: 'login',
        component: Login,
        meta: {
            canJump: true
        },
    },
    {
        path: "/index",
        name: "index",
        component: Index,
        children: [
            {
                path: "/RestPassword",
                name: "RestPassword",
                component: RestPassword,
            },
            {
                path: "/DishPage",
                name: "DishPage",
                component: DishPage,
            },
            {
                path: "/AddDishPage",
                name: "AddDishPage",
                component: AddDishPage,
            },
            {
                path: "/UpdateDishPage",
                name: "UpdateDishPage",
                component: UpdateDishPage,
            },
            {
                path: "/DishCategoriesPage",
                name: "DishCategoriesPage",
                component: DishCategoriesPage,
            },
            {
                path: "/RankingListPage",
                name: "RankingListPage",
                component: RankingListPage,
            },
            {
                path: "/CategoriesDetailPage",
                name: "CategoriesDetailPage",
                component: CategoriesDetailPage,
            },
            {
                path: "/OrdersPage",
                name: 'OrdersPage',
                component: OrdersPage
            },
            {
                path: "/RefundOrderPage",
                name: 'RefundOrderPage',
                component: RefundOrderPage,
            },
            {
                path: "/MembersPage",
                name: 'MembersPage',
                component: MembersPage,
            }
        ],
        meta: {
            canJump: false
        },

    },
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})
router.beforeEach((to, from, next) => {
    if (to.meta.canJump || localStorage.getItem('token')) {
        next();
    } else {
        message.warn("请验证身份")
    }
})

export default router
